"""
python 操作redis数据库

"""
import redis

client = redis.StrictRedis(password='123456')
print(client)

client.set('username', 'admin')

print(client.keys('*'))
# 字符串的
print(client.get('username').decode())
# 判断键是否存在  返回值1：存在 0：不存在
r = client.exists('username')
print(r)
# # 删除
# r = client.delete('username')
# print("删除", r)

r = client.type('username')
print(r)

r = client.expire('username', 50)
print('expire', r)

r = client.ttl('username')
print('ttl', r)

# r = client.flushdb()
# print('flushdb', r)

r = client.dbsize()
print('dbsize', r)

# 释放资源
client.close()
